(function() {
  var Config, ConnectRedis, Express, HttpHandler, Logger, RedisClient, app, listenPort, redisStore;

  Express = require('express');

  Config = require('./config');

  Logger = require('log4js').getLogger();

  RedisClient = require('./models/redis_client');

  ConnectRedis = require('connect-redis')(Express);

  HttpHandler = require('./helpers/http_handler');

  app = Express.createServer();

  redisStore = new ConnectRedis({
    client: RedisClient
  });

  app.configure(function() {
    app.set('view', "" + __dirname + "/views");
    app.set('view engine', 'jade');
    if (!Config.debug) {
      app.use(Express.logger());
    }
    app.use(HttpHandler.staticHandler);
    app.use(Express.bodyParser());
    app.use(Express.cookieParser());
    app.use(Express.session({
      key: Config.session.key,
      secret: Config.session.secret,
      store: redisStore
    }));
    app.use(Express.methodOverride());
    app.use(HttpHandler.cacheHandler);
    return app.use(app.router);
  });

  app.configure('production', function() {
    app.use(Express.errorHandler());
    return process.on('uncaughtException', function(err) {
      return Logger.error("uncaughtException:" + err);
    });
  });

  app.configure('development', function() {
    return app.use(Express.errorHandler({
      dumpExceptions: true,
      showStack: true
    }));
  });

  require('./apps/ys/routes')(app);

  listenPort = Config.server.port;

  app.listen(listenPort);

  Logger.info("express linsten on port %d in %s mode", listenPort, app.settings.env);

}).call(this);
